package com.yulongtian.weekCompetition.month202212.week1;

import java.util.Arrays;

/**
 * 第 322 场周赛
 * 可
 *
 * @author yulongTian
 * @create 2022-12-04 10:30
 */
public class Test01 {
    public static void main(String[] args) {
        System.out.println(isCircularSentence("Leetcode is cool"));
    }

    public static boolean isCircularSentence(String sentence) {
        String[] split = sentence.split(" ");

        int len = split.length;
        if (len == 1) {
            char c1 = split[0].charAt(0);
            char c2 = split[0].charAt(split[0].length() - 1);
            return c1 == c2;
        }

        char c1 = split[0].charAt(0);
        char c2 = split[len - 1].charAt(split[len - 1].length() - 1);

        if (c1 != c2) {
            return false;
        }


        for (int i = 0; i < len - 1; i++) {
            char cPre = split[i].charAt(split[i].length() - 1);
            char cLatter = split[i + 1].charAt(0);
            if (cPre != cLatter) {
                return false;
            }


        }

        return true;
    }

}
